package com.xhh.microfin.dispatch.controller;

import com.xhh.microfin.dispatch.common.utils.R;
import com.xhh.microfin.dispatch.exception.OrderExistException;
import com.xhh.microfin.dispatch.model.vo.OrderVo;
import com.xhh.microfin.dispatch.model.vo.ResponseVo;
import com.xhh.microfin.dispatch.model.vo.query.OrderQueryVo;
import com.xhh.microfin.dispatch.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 003035
 * @Date: 2019/1/16
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * @api {post} /order/add 新增订单
     * @apiName addOrder
     * @apiGroup Order
     * @apiParam {Number} userId Users unique ID.
     * @apiParam {Number} loanAmount loan amount
     * @apiParam {String} orderSn order sn
     * @apiParam {String} productCode product code
     * @apiSuccessExample {json} Success-Response:
     * {
     * "status": 1,
     * "message": "success",
     * "data": null
     * }
     * @apiErrorExample {json} Error-Response:
     * {
     * "status":0,
     * "message":"增加订单失败"
     * }
     */
    @PostMapping("add")
    public R add(@RequestBody OrderVo orderVo) {

        try {
            orderService.add(orderVo);

        } catch (OrderExistException e) {
            return R.error(e.getMessage());
        }
        return R.ok();
    }

    /**
     * @api {post} /order/task 订单任务节点
     * @apiName listOrder
     * @apiGroup Order
     * @apiParam {String} orderSn order sn
     * @apiSuccessExample {json} Success-Response:
     * {
     * "status": 1,
     * "message": "success",
     * "data": [
     *      {
     *          "code":"start",
     *          "status":"已完成",
     *          "name":"开始"
     *      },
     *      {
     *          "code":"precheck",
     *          "name":"前置校验",
     *          "status":"已完成"
     *      },{
     *          "code":"risk",
     *          "name":"风控",
     *          "status":"处理中"
     *      }
     * ]
     * }
     */
    @PostMapping("task")
    public R list(@RequestBody OrderQueryVo orderQueryVo) {

        return null;
    }

    @PostMapping("process")
    public R process(@RequestBody String orderSn) {
        orderService.process(orderSn);
        return R.ok();
    }
}
